package com.four.dailymanage.chamber.dao;

import com.four.dailymanage.chamber.entity.Chamber;
import com.four.dailymanage.chamber.entity.ChamberReserve;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ChamberReserveDao {
    //分页
    @Select("<script>" +
            "SELECT * FROM chamber_reserve" +
            "  <where>" +
            "    <if test=\" cname != null\">" +
            "       cname = #{cname} " +
            "    </if>" +
            "    <if test=\" applyDept != null\">" +
            "       and applyDept = #{applyDept} " +
            "    </if>" +
            "    <if test=\" reserveStatus != null\">" +
            "       and reserveStatus = #{reserveStatus} " +
            "    </if>" +
            "    <if test=\" startDt != null\">" +
            "      and startDt = #{startDt} " +
            "    </if>" +
            "    <if test=\" applyMan != null\">" +
            "    <bind name=\"Key\" value=\"'%'+applyMan+'%'\"/>"+
            "      and applyMan like #{Key} " +
            "    </if>" +
            "</where>"+
            "limit #{start},#{size}"+
            "</script>")

    public List<ChamberReserve> getChamberReserveByCon(int start, int size, String cname,String applyDept,String reserveStatus,String startDt,String applyMan);

    @Select("<script>" +
            "select count(*) from chamber" +
            "  <where>" +
            "    <if test=\" cname != null\">" +
            "       cname = #{cname} " +
            "    </if>" +
            "    <if test=\" applyDept != null\">" +
            "       and applyDept = #{applyDept} " +
            "    </if>" +
            "    <if test=\" reserveStatus != null\">" +
            "       and reserveStatus = #{reserveStatus} " +
            "    </if>" +
            "    <if test=\" startDt != null\">" +
            "      and startDt = #{startDt} " +
            "    </if>" +
            "    <if test=\" applyMan != null\">" +
            "    <bind name=\"Key\" value=\"'%'+applyMan+'%'\"/>"+
            "      and applyMan like #{Key} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public  int countChamberReserve(String cname,String applyDept,String reserveStatus,String startDt,String applyMan);


    //添加一条预约消息
    @Insert("insert into chamber_reserve(applyDept,meeting,cname,startDt,endDt,contestant,content,isMonogram,MonogramCon,chamberType,applyMan,isScreen,note,reserveStatus)" +
            " values (#{applyDept},#{meeting},#{cname},#{startDt},#{endDt},#{contestant},#{content},#{isMonogram},#{MonogramCon}," +
            "#{chamberType},#{applyMan},#{isScreen},#{note},#{reserveStatus})")
    public int addReserve(ChamberReserve chamberReserve);

    //检查某时间段内会议室是否被占用
    @Select("select * from chamber_reserve where cname=#{cname} and startDt=#{startDt} and endDt=#{endDt}")
    public ChamberReserve checkRoom(String cname,String startDt,String endDt);
    //更新预约状态
    @Update("<script>" +
            "update  chamber_reserve " +
            "        <set>" +
            "            <if test=\"null!= reserveStatus\">" +
            "                reserveStatus =#{reserveStatus}," +
            "            </if>" +
            "            <if test=\"null!= chamberNo\">" +
            "                chamberNo =#{chamberNo}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public  int  UpdateStatusById(ChamberReserve chamberReserve);
}
